package cn.elwy.rcp.kit.service.internal;

import org.eclipse.e4.core.contexts.ContextFunction;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.model.application.MApplication;

import cn.elwy.rcp.kit.model.ITodoService;

public class TodoServiceContextFunction extends ContextFunction {
  @Override
  public Object compute(IEclipseContext context, String contextKey) {
    ITodoService todoService = ContextInjectionFactory.make(MyTodoServiceImpl.class, context);

    MApplication app = context.get(MApplication.class);
    IEclipseContext appCtx = app.getContext();
    appCtx.set(ITodoService.class, todoService);

    return todoService;
  }
}
